#include <iostream>
#include <vector>
#include <memory>

class IOrderSaver {
public:
    virtual ~IOrderSaver() = default;
    virtual void save(const std::vector<std::string>& items) = 0;
};

class FileOrderSaver : public IOrderSaver {
public:
    void save(const std::vector<std::string>& items) override {
        std::cout << "Сохранение заказа в файл..." << std::endl;
    }
};

class DatabaseOrderSaver : public IOrderSaver {
public:
    void save(const std::vector<std::string>& items) override {
        std::cout << "Сохранение заказа в базу данных..." << std::endl;
    }
};

class IOrder {
public:
    virtual ~IOrder() = default;
    virtual void addItem(const std::string& item) = 0;
    virtual void printOrder() const = 0;
};

class Order : public IOrder {
protected:
    std::vector<std::string> items;
    std::unique_ptr<IOrderSaver> saver;

public:
    Order(std::unique_ptr<IOrderSaver> saver) : saver(std::move(saver)) {}

    void addItem(const std::string& item) override {
        items.push_back(item);
    }

    void printOrder() const override {
        std::cout << "Заказ: ";
        for (const auto& item : items) {
            std::cout << item << " ";
        }
        std::cout << std::endl;
    }

    virtual void save() {
        if (saver) {
            saver->save(items);
        }
    }
};

class OnlineOrder : public Order {
public:
    OnlineOrder(std::unique_ptr<IOrderSaver> saver) : Order(std::move(saver)) {}
};

int main() {
    auto fileSaver = std::make_unique<FileOrderSaver>();
    auto dbSaver = std::make_unique<DatabaseOrderSaver>();

    Order order(std::move(fileSaver));
    order.addItem("A");
    order.addItem("B");
    order.printOrder();
    order.save();

    OnlineOrder onlineOrder(std::move(dbSaver));
    onlineOrder.addItem("C");
    onlineOrder.printOrder();
    onlineOrder.save();

    return 0;
}
